﻿using Microsoft.AspNetCore.Http;
using System;
using System.Text;
using System.Web;
using TradeDataAPI.Core.Configuration;

namespace TradeDataAPI.Core.Common
{
    public class CookieHelper
    {
        public static void SetCookie(HttpResponse response, string key, string value, int minutes)
        {
            response.Cookies.Append(key, HttpUtility.UrlEncode(value, Encoding.GetEncoding("UTF-8")), new CookieOptions
            {
                HttpOnly = false,
                Secure = false,
                SameSite = SameSiteMode.Lax,
                Path = "/", // 确保Cookie在整个站点范围内可用
                Domain = AppSetting.GetSection("Saml2")["CreateCookie"], // 如果前端和后端在不同的子域下，设置域
                MaxAge = TimeSpan.FromMinutes(minutes)
            });
        }
    }
}
